<?php

abstract class Urls
{
	private static $Patterns;
	
	public static function Patterns($Patterns = array())
	{
		self::$Patterns = $Patterns;
	}
	
	public static function GetPatterns()
	{
		return self::$Patterns;
	}
	
	public static function Find($Url)
	{
		foreach (self::$Patterns as $Pattern => $Options)
		{
			$Pattern = str_replace(array('(:num)'), array('([0-9]+)'), $Pattern);
			
			if ($Url == $Pattern)
			{
				return $Options;
			}
			elseif (preg_match("#^{$Pattern}$#u", $Url))
			{
				if ($ArgumentCount = substr_count($Pattern, '('))
				{
					for ($i = 0; $i < $ArgumentCount; ++$i)
					{
						$Tags[] = '$' . ($i + 1);
					}
					
					$Options['Arguments'] = explode('/', preg_replace("#^{$Pattern}$#u", implode('/', $Tags), $Url));
				}
				
				return $Options;
			}
		}
		
		die('404');
	}
}